<?php

namespace App\Http\Requests\client;

use App\Http\ValidateResult;
use Illuminate\Support\Facades\Validator;

trait PreTakeRequest
{
    public static function add_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'contact' => 'required',
            'company' => 'required',
            'mobile' => 'required',
            'pre_time' => 'required',
            'province_id' => 'required',
            'city_id' => 'required',
//            'district_id' => 'required',
            'address' => 'required',
            'goods' => 'required',
        ], [
            'contact.required' => '请填写联系人',
            'company.required' => '请填写公司',
            'mobile.required' => '请填写联系电话',
            'pre_time.required' => '请选择取件日期',
            'province_id.required' => '请选择省',
            'city_id.required' => '请选择市',
//            'district_id.required' => '请选择区',
            'address.required' => '请填写详细地址',
            'goods.required' => '请填写货物信息',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }


    public static function goods_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'length' => 'required|numeric',
            'width' => 'required|numeric',
            'height' => 'required|numeric',
            'weight' => 'required|numeric'
        ], [
            'length.required' => '请填写长',
            'width.required' => '请填写宽',
            'height.required' => '请填写高',
            'weight.required' => '请选择重量',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

    public static function arrange_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'driver_id' => 'required',
            'car_id' => 'required',
            'warehouse_id' => 'required',
        ], [
            'driver_id.required' => '请选择司机',
            'car_id.required' => '请选择车辆',
            'warehouse_id.required' => '请选择仓库',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }
}
